//
//  LXCustomTableViewCell.m
//  10_CustomTableViewCell
//
//  Created by GivenBmli on 16/7/27.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "LXCustomTableViewCell.h"
#import "UIView+Frame.h"
@interface LXCustomTableViewCell ()

@end

@implementation LXCustomTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _nemsImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
        _nemsImageView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_nemsImageView];
        _titileLabel  = [[UILabel alloc]initWithFrame:CGRectZero];
        _titileLabel.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_titileLabel];
        _descriptopnlabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _descriptopnlabel.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_descriptopnlabel];
        _numberCountsLaberl = [[UILabel alloc]initWithFrame:CGRectZero];
        _numberCountsLaberl.backgroundColor = [UIColor yellowColor];
        [_descriptopnlabel addSubview:_numberCountsLaberl];
//        lable上不能加控件
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat leftMargin = 5;
    CGFloat topMatgin = 5;
    CGFloat bottomMatgin = 5;
    CGFloat rightMatgin  = 5;
    CGFloat middileMargin = 5;
    CGFloat titleLabelHeight = 30;
    _nemsImageView.frame = CGRectMake(leftMargin, topMatgin, self.contentView.ml_width / 3, self.contentView.ml_height - topMatgin - bottomMatgin );
    
    CGFloat titileLabelX =_nemsImageView.ml_x + _nemsImageView.ml_width + 5;
    _titileLabel.frame = CGRectMake(titileLabelX, topMatgin, self.contentView.ml_width - titileLabelX -rightMatgin,titleLabelHeight);
    CGFloat descriptopnlabelY = topMatgin + _titileLabel.ml_height + middileMargin;
    _descriptopnlabel.frame = CGRectMake(titileLabelX, descriptopnlabelY, _titileLabel.ml_width, self.contentView.ml_height - descriptopnlabelY - bottomMatgin);
    CGFloat numberCountsX = _descriptopnlabel.ml_width *3 / 5;
    CGFloat numberCountWidth = _descriptopnlabel.ml_width * 2 / 5;
    CGFloat numberCountHeight = _descriptopnlabel.ml_height / 2;
//    判断父视图是不是_descriptopnlabel
//    if (_numberCountsLaberl.superview == _descriptopnlabel) {
//    改变_numberCountsLaberl 的父视图
    [_descriptopnlabel addSubview:_numberCountsLaberl];
        _numberCountsLaberl.frame = CGRectMake(numberCountsX, numberCountHeight, numberCountWidth, numberCountHeight);
    //     视图坐标系转换
   CGRect newRect =  [_numberCountsLaberl .superview convertRect:_numberCountsLaberl.frame toView:self.contentView];
    _numberCountsLaberl.frame = newRect;
    [self.contentView addSubview:_numberCountsLaberl];
//    }
}

- (void)setNewsObjiect:(NewsObject *)newsObjiect {
    _newsObjiect = newsObjiect;
    self.nemsImageView.image = [UIImage imageNamed:newsObjiect.newsImage];
    self.titileLabel.text = newsObjiect.newsTitle;
    self.descriptopnlabel.text = newsObjiect.newsDescripition;
    self.numberCountsLaberl.text = newsObjiect.newsNumberCount;

}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
